@model LanLordz.Models.ForumThreadModel
@{
    var controller = this.ViewContext.Controller as LanLordzBaseController;
    ViewBag.Title = (string.IsNullOrEmpty(this.Model.Thread.Title) ? "(No Title)" : this.Model.Thread.Title) + " | View Thread";
}
@section headers
{
    <script type="text/javascript">
        $(function() {
            $('.ForumPoll').each(function() {
                var $current = $(this);
                $.post($current.attr('href') + "?partial=1", function(data) {
                    $current.replaceWith('<div class="ForumPoll">' + data + '</div>');
                })
            });
        });
    </script>
}
    <div class="ForumNavigator"><span>@Html.ActionLink(controller.Config.SiteName + " Forum Index", "Index")</span> &gt; <span>@Html.ActionLink(this.Model.Thread.Forum.Name, "ViewForum", new { id = this.Model.Thread.Forum.ForumID })</span> &gt; <span>@(string.IsNullOrEmpty(this.Model.Thread.Title) ? "(No Title)" : this.Model.Thread.Title)</span></div>
    <div class="ThreadPagination">@Html.Partial("PaginationView", Model.PageInfo)</div>
    <table class="PostsTable" cellpadding="0" cellspacing="0">
     <tr>
      <th>Author</th>
      <th>Post</th>
     </tr>
     @{
     var lastPost = Model.Posts.OrderByDescending(p => p.Post.CreateDate).FirstOrDefault();
     }
     @foreach (var post in Model.Posts.OrderBy(p => p.Post.CreateDate))
     {
     <tr class="Post">
      <td class="PostAuthor">
       @Html.UserLink(post.UserID, post.Username)<br />
       @Html.UserAvatar(post.UserID, post.Username, post.UserHasAvatar, post.UserEmail)<br />
       Posts: @post.UserPosts<br />
       Joined: @post.UserJoinedDate.ToShortDateString()
       @if (!string.IsNullOrEmpty(post.UserTitle))
       {
       <div class="PostAuthorBadge PostAuthorUserBadge">@post.UserTitle</div>
       }
       @if (!string.IsNullOrEmpty(post.GroupTitle))
       {
       <div class="PostAuthorBadge PostAuthorGroupBadge">@post.GroupTitle</div>
       }
       @if (!string.IsNullOrEmpty(post.PostCountTitle))
       {
       <div class="PostAuthorBadge PostAuthorPostCountBadge">@post.PostCountTitle</div>
       }
      </td>
      <td class="PostData">
       <div class="PostHeader">
        <div class="PostTitle"><a name="@post.Post.PostID">@post.Post.Title</a></div>
        <div class="PostDate">Posted: @controller.ConvertDateTime(post.Post.CreateDate)</div>
        <div class="PostTools">
        @if (Model.UserAccess.CanPost && (!Model.Thread.IsLocked || Model.UserAccess.CanModerate))
        {
         <div class="PostToolReply">@Html.ActionLink("Reply", "CreatePost", new { replyto = post.Post.PostID })</div>
        }
        @if (Model.UserAccess.CanPost && controller.CurrentUser != null && controller.CurrentUser.UserID == post.UserID && (!Model.Thread.IsLocked || Model.UserAccess.CanModerate))
        {
         <div class="PostToolEdit">@Html.ActionLink("Edit", "EditPost", new { id = post.Post.PostID })</div>
        }
        @if (Model.UserAccess.CanModerate && controller.CurrentUser != null && controller.CurrentUser.UserID != post.UserID)
        {
         <div class="PostToolModerate">@Html.ActionLink("Moderate", "EditPost", new { id = post.Post.PostID })</div>
        }
        @if (Model.UserAccess.CanModerate || (Model.UserAccess.CanPost && controller.CurrentUser != null && controller.CurrentUser.UserID == post.UserID && post.Post.PostID == lastPost.Post.PostID && !Model.Thread.IsLocked))
        {
         <div class="PostToolDelete">@Html.ActionLink("Delete", "DeletePost", new { id = post.Post.PostID })</div>
        }
        </div>
       </div>
       <div class="PostText">
@Html.BBCode(post.Post.Text)
@if (!string.IsNullOrEmpty(post.UserSignature))
{
<hr/>
@Html.BBCode(post.UserSignature)
}
       </div>
      </td>
     </tr>
     }
    </table>
    <div class="ThreadPagination">@Html.Partial("PaginationView", Model.PageInfo)</div>
    @if (Model.UserAccess.CanPost)
    {
    <div class="ThreadTools">
     <div class="ThreadToolsNewPost">
      @Html.ActionLink("New Post", "CreatePost", new { thread = Model.Thread.ThreadID })
     </div>
    </div>
    }
